package com.KMGSoftworks.ShoppingList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;


public class CreateList extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_list);

        InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        
    }

    public void handleSaveClick(View view) {
   	
    	final EditText txtName = (EditText) findViewById(R.id.txtName);

        InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
    	imm.hideSoftInputFromWindow(txtName.getWindowToken(), 0);
    	
    	String name = txtName.getText().toString();
    	
    	if(name.length() == 0){
	      	Context context = getApplicationContext();
	    	CharSequence text = "List name is required!";
	
	    	Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
	    	toast.setGravity(Gravity.TOP, 0, 30);
	    	toast.show();	
    	}
    	else {
	    	Intent intent = new Intent();
	    	intent.putExtra("ListName", name);
	    	setResult(RESULT_OK, intent);
	    	this.finish();
    	}
    
    }
      
      
	
}
